﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TaskManage
{
    public partial class FormLogin : Form
    {
        public FormLogin()
        {
            InitializeComponent();
        }

        private void FormLogin_Load(object sender, EventArgs e)
        {

        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            string uid = this.textBoxUserName.Text;
            string passwd = this.textBoxPasswd.Text;
            string qstr = "SELECT Count(uid) FROM users_info WHERE uname = '" + uid + "' AND upasswd = '" + passwd + "'";
            DBConnect dbConn = new DBConnect();
            int cnt = dbConn.Count(qstr);
            if (cnt == 1)
            {
                FormMain MainForm = new FormMain();

                string qstr2 = "SELECT upriority,uid FROM users_info WHERE uname = '" + uid + "' AND upasswd = '" + passwd + "'";
                DataSet ds = dbConn.Query(qstr2);
                if (ds == null) return;
                DataTable dt = ds.Tables[0];
                DataRow row = dt.Rows[0];
                MainForm.upriority = row[0].ToString();
                MainForm.uname = uid;
                MainForm.uid = row[1].ToString();
                MainForm.Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("Unexpected USERNAME or PASSWORD!","Error");
            }
        }
    }
}
